# -*- encoding: utf-8 -*-
import time, datetime
from odoo import models, fields, api, _

from odoo.tools import float_compare, float_round
from odoo.addons import base_cw
from odoo.tools import float_compare, float_round
from odoo.exceptions import UserError, RedirectWarning, ValidationError
from dateutil.relativedelta import relativedelta


class account_statement(models.Model):
    _inherit = 'account.statement'
    _description = u'对帐单'

    # 产生发票
    def action_create_invoice(self):
        self.ensure_one()
        super(account_statement, self).action_create_invoice()
        for line in self.invoice_id.invoice_line_ids:
            if line.account2_id.sub_account_type == 'has':
                line.sub_account_id = self.partner_id.id
            if not line.account1_id:
                line.account1_id = self.invoice_id.get_pay_account_product_type(self.invoice_id.type, line.product_id.product_type)
